package com.dce.dev.api.dto.base;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.annotations.ApiModelProperty;

public class ResultDTO<T>implements Serializable  {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2935004512229175672L;
	
    /**
     * 对象数据
     */
    @ApiModelProperty(value = "业务数据", position = 1)
    private T data;
    
    @ApiModelProperty(value = "错误编号", position = 2)
    private String code;
    
    @ApiModelProperty(value = "错误信息", position = 3)
    private String message;
    
    ///////////////////////////////////////
    // Getter
    ///////////////////////////////////////
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty(value = "data", index = 2)
    public T getData() {
        return this.data;
    }

    ///////////////////////////////////////
    // Setter
    ///////////////////////////////////////
    public void setData(final T data) {
        this.data = data;
    }

    ///////////////////////////////////////
    // Getter
    ///////////////////////////////////////
	public String getCode() {
		return code;
	}
    ///////////////////////////////////////
    // Setter
    ///////////////////////////////////////
	public void setCode(String code) {
		this.code = code;
	}

    ///////////////////////////////////////
    // Getter
    ///////////////////////////////////////
	public String getMessage() {
		return message;
	}
    ///////////////////////////////////////
    // Setter
    ///////////////////////////////////////
	public void setMessage(String message) {
		this.message = message;
	}
    
    ///////////////////////////////////////
    // Constructor
    ///////////////////////////////////////
    public ResultDTO() {
    }    
    
    
	///////////////////////////////////////
	// Builder
	///////////////////////////////////////
	public static ResultDTO<Void> success() {
		final ResultDTO<Void> result = new ResultDTO<>();
		result.setCode("200");
		return result;
	}
	
	public static ResultDTO<Void> success(final String message) {
		final ResultDTO<Void> result = new ResultDTO<>();
		result.setCode("200");
		result.setMessage(message);
		return result;
	}

	public static <T> ResultDTO<T> success(final T data) {
		final ResultDTO<T> result = new ResultDTO<>();
		result.setCode("200");
		result.setData(data);
		return result;
	}
	
	
	public static <T> ResultDTO<T> success(final T data,final String message) {
		final ResultDTO<T> result = new ResultDTO<>();
		result.setCode("200");
		result.setMessage(message);
		result.setData(data);
		return result;
	}
	
	public static ResultDTO<Void> failure(final String code,final String message) {
		final ResultDTO<Void> result = new ResultDTO<>();
		result.setCode(code);
		result.setMessage(message);
		return result;
	}
	
	public static <T> ResultDTO<T> failure(final T data, final String code,final String message) {
		final ResultDTO<T> result = new ResultDTO<>();
		result.setCode(code);
		result.setMessage(message);
		result.setData(data);
		return result;
	}
    

}
